package com.easy.dn.ui.usercenter.model;

import com.easy.common.commonutils.SPUtils;
import com.easy.dn.api.Api;
import com.easy.dn.api.ApiService;
import com.easy.dn.app.GlobalApplication;
import com.easy.dn.bean.CodeBean;
import com.easy.dn.bean.CodeVerificationBean;
import com.easy.dn.bean.UserInfoBean;
import com.easy.dn.ui.usercenter.contract.RegisterContract;

import java.util.Map;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by DN on 2017/5/3.
 */


public class RegisterModel implements RegisterContract.Model {
    @Override
    public Observable<UserInfoBean> ObtainUserInfoData(Map<String, String> map) {
        return Api.getInstance().getProxy(ApiService.class).getUserInfo(Api.getCacheControl(), map).
                subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
    }

    @Override
    public Observable<CodeBean> ObtainCodeInfoData(Map<String, String> map) {
        return Api.getInstance().get(ApiService.class).getCookieData(Api.getCacheControl(), map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

    @Override
    public Observable<UserInfoBean> ObtainRegistgerData(Map<String, String> map) {
        return  Api.getInstance().get(ApiService.class)
                .getRegisterData( Api.getCacheControl(), map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

    @Override
    public Observable<CodeVerificationBean> ObtainVerificationData(Map<String, String> map) {
        return Api.getInstance().get(ApiService.class)
                .getVerification(SPUtils.getSharedStringData(GlobalApplication.getInstance(), "Cookie"), Api.getCacheControl(), map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }
}
